home *** CD-ROM | disk | FTP | other *** search
- /* Stuff heavily dependent on the configuration info in config.h */
-
- #include <stdio.h>
- #include <dos.h>
- #include "global.h"
- #include "mbuf.h"
- #include "proc.h"
- #include "cmdparse.h"
- #include "config.h"
- #include "daemon.h"
- #include "timer.h"
- #include "iface.h"
- #include "ppp.h"
- #include "slip.h"
- #include "usock.h"
- #include "socket.h"
- #include "kiss.h"
- #include "enet.h"
- #include "ax25.h"
- #include "netrom.h"
- #include "ip.h"
- #include "tcp.h"
- #include "udp.h"
- #include "commands.h"
- #include "rspf.h"
-
- static int dostart __ARGS((int argc,char *argv[],void *p));
- static int dostop __ARGS((int argc,char *argv[],void *p));
- static int domessage __ARGS((int argc,char *argv[],void *p));
-
- struct mbuf *Hopper;
- unsigned Nsessions = NSESSIONS;
- int32 Heapsize = HEAPSIZE * (long)1024;
-
- /* Free memory threshold, below which things start to happen to conserve
- * memory, like issuing source quenches and refusing connects
- */
- int32 Memthresh = MTHRESH;
-
- /* daemons to be run at startup time */
- struct daemon Daemons[] = {
- "killer", 200, killer,
- "timer", 1024, timerproc,
- "network", 1536, network,
- "keyboard", 250, keyboard,
- NULLCHAR, 0, NULLVFP
- };
-
- struct iftype Iftypes[] = {
- /* This entry must be first, since Loopback refers to it */
- "None", NULL, NULL, NULL,
- NULL, TYPE_NONE, 0,
-
- #ifdef AX25
- "AX25", ax_send, ax_output, pax25,
- setcall, TYPE_AX25, AXALEN,
- #endif
-
- #ifdef SLIP
- "SLIP", slip_send, NULL, NULL,
- NULL, TYPE_IP, 0,
- #endif
-
- #ifdef ETHER
- /* Note: NULL is specified for the scan function even though
- * gether() exists because the packet drivers don't support
- * address setting.
- */
- "Ethernet", enet_send, enet_output, pether,
- NULL, TYPE_ETHER, EADDR_LEN,
- #endif
-
- #ifdef NETROM
- "NETROM", nr_send, NULL, pax25,
- setcall, TYPE_NETROM, AXALEN,
- #endif
- #ifdef PPP
- "PPP", ppp_send, ppp_output, NULL,
- NULL, TYPE_PPP, 0,
- #endif /* PPP */
-
- NULLCHAR
- };
-
- /* Command lookup and branch tables */
- struct cmds Cmds[] = {
- /* The "go" command must be first */
- "", go, 0, 0, NULLCHAR,
- "abort", doabort, 0, 0, NULLCHAR,
- "amiga", doamiga, 0, 0, NULLCHAR,
- #if (defined(AX25) || defined(ETHER) || defined(APPLETALK))
- "arp", doarp, 0, 0, NULLCHAR,
- #endif
- #ifdef ASY
- "asystat", doasystat, 0, 0, NULLCHAR,
- #endif
- "attach", doattach, 0, 2,
- "attach <hardware> <hw specific options>",
- #ifdef AX25
- "ax25", doax25, 0, 0, NULLCHAR,
- #endif
- #ifdef MAILBOX
- "bbs", dobbschat, 1024, 0, NULLCHAR,
- #endif
- /* This one is out of alpabetical order to allow abbreviation to "c" */
- #ifdef AX25
- "connect", doconnect, 1024, 3,"connect <interface> <callsign>",
- #endif
- #ifdef CHATNODE
- "chatnode", dobbschat, 1024, 0, NULLCHAR,
- #endif
- "close", doclose, 0, 0, NULLCHAR,
- "disconnect", doclose, 0, 0, NULLCHAR,
- #ifdef DIGGER
- "digger", dodigger, 0, 0, NULLCHAR,
- #endif
- "detach", dodetach, 0, 2, "detach <interface>",
- "domain", dodomain, 0, 0, NULLCHAR,
- "echo", doecho, 0, 0, NULLCHAR,
- "eol", doeol, 0, 0, NULLCHAR,
- "escape", doescape, 0, 0, NULLCHAR,
- "exit", doexit, 0, 0, NULLCHAR,
- "finger", dofinger, 1024, 2, "finger name@host",
- "ftp", doftp, 2048, 2, "ftp <address>",
- #ifdef FTPTDISC
- "fttimeout", doftptdisc, 0, 0, NULLCHAR,
- #endif
- "ftpdown", doftpdown, 0, 0, NULLCHAR,
- "help", dohelp, 0, 0, NULLCHAR,
- "hopcheck", dohop, 0, 0, NULLCHAR,
- "hostname", dohostname, 0, 0, NULLCHAR,
- "icmp", doicmp, 0, 0, NULLCHAR,
- "ifconfig", doifconfig, 0, 0, NULLCHAR,
- "ip", doip, 0, 0, NULLCHAR,
- "kick", dokick, 0, 0, NULLCHAR,
- "less", doless, 512, 2, "less <filename>",
- #ifdef MAILBOX
- "mbox", dombox, 0, 0, NULLCHAR,
- #endif
- "mem", domem, 0, 0, NULLCHAR,
- "message", domessage, 0, 2, "message <socket> <msg>",
- #ifdef AX25
- "mode", domode, 0, 2, "mode <interface>",
- #endif
- #ifdef NETROM
- "netrom", donetrom, 0, 0, NULLCHAR,
- #ifdef NRS
- "nrstat", donrstat, 0, 0, NULLCHAR,
- #endif /* NRS */
- #endif /* NETROM */
- #ifdef NNTP
- "nntp", donntp, 0, 0, NULLCHAR,
- #endif
- "param", doparam, 0, 2, "param <interface>",
- "ping", doping, 512, 2, "ping <host> [<length> [<interval> [incflag]]]",
- #ifdef POP
- "pop", dopop, 0, 0, NULLCHAR,
- #endif
- #ifdef PPP
- "ppp", dopppcontrol, 0, 0, NULLCHAR,
- #endif /* PPP */
- "ps", ps, 0, 0, NULLCHAR,
- "record", dorecord, 0, 0, NULLCHAR,
- "remote", doremote, 0, 3, "remote [-p port] [-k key] [-a kickaddr] <address> exit|reset|kick",
- "reset", doreset, 0, 0, NULLCHAR,
- #ifdef RLOGINCLI
- "rlogin", dorlogin, 2048, 2, "rlogin <address>",
- #endif
- #ifdef RIP
- "rip", dorip, 0, 0, NULLCHAR,
- #endif
- "route", doroute, 0, 0, NULLCHAR,
- #ifdef RSPF
- "rspf", dorspf, 0, 0, NULLCHAR,
- #endif /* RSPF */
- "session", dosession, 0, 0, NULLCHAR,
- "smtp", dosmtp, 0, 0, NULLCHAR,
- "socket", dosock, 0, 0, NULLCHAR,
- "source", dosource, 0, 2, "source <filename>",
- #ifdef SERVERS
- "start", dostart, 0, 2, "start <servername>",
- "stop", dostop, 0, 2, "stop <servername>",
- #endif
- "status", dostatus, 0, 0, NULLCHAR,
- "tcp", dotcp, 0, 0, NULLCHAR,
- "telnet", dotelnet, 1024, 2, "telnet <address>",
- #ifdef TRACE
- "trace", dotrace, 0, 0, NULLCHAR,
- #endif
- "ttylink", dotelnet, 1024, 2, "ttylink <address>",
- "udp", doudp, 0, 0, NULLCHAR,
- "upload", doupload, 0, 0, NULLCHAR,
- "?", dohelp, 0, 0, NULLCHAR,
- NULLCHAR, NULLFP, 0, 0,
- "Unknown command; type \"?\" for list",
- };
-
- /* List of supported hardware devices */
- struct cmds Attab[] = {
- #ifdef PC_EC
- /* 3-Com Ethernet interface */
- "3c500", ec_attach, 0, 7,
- "attach 3c500 <address> <vector> arpa <label> <buffers> <mtu> [ip_addr]",
- #endif
- #ifdef ASY
- /* Ordinary PC asynchronous adaptor */
- "asy", asy_attach, 0, 8,
- #ifndef AMIGA
- "attach asy <address> <vector> slip|ax25|nrs|ppp <label> <buffers> <mtu> <speed> [ip_addr]",
- #else
- "attach asy <driver> <unit> slip|ax25|nrs|ppp <label> <buffers> <mtu> <speed> [ip_addr]",
- #endif /* AMIGA */
- #endif /* ASY */
- #ifdef KISS
- /* Multi-port KISS interface piggy-backing on ASY interface. */
- "kiss", kiss_attach, 0, 4,
- "attach kiss <asy_interface_label> <port> <label> [mtu]",
- #endif /* KISS */
- #ifdef PC100
- /* PACCOMM PC-100 8530 HDLC adaptor */
- "pc100", pc_attach, 0, 8,
- "attach pc100 <address> <vector> ax25 <label> <buffers>\
- <mtu> <speed> [ip_addra] [ip_addrb]",
- #endif
- #ifdef DRSI
- /* DRSI PCPA card in low speed mode */
- "drsi", dr_attach, 0, 8,
- "attach drsi <address> <vector> ax25 <label> <bufsize> <mtu>\
- <chan a speed> <chan b speed> [ip addr a] [ip addr b]",
- #endif
- #ifdef EAGLE
- /* EAGLE RS-232C 8530 HDLC adaptor */
- "eagle", eg_attach, 0, 8,
- "attach eagle <address> <vector> ax25 <label> <buffers>\
- <mtu> <speed> [ip_addra] [ip_addrb]",
- #endif
- #ifdef HAPN
- /* Hamilton Area Packet Radio (HAPN) 8273 HDLC adaptor */
- "hapn", hapn_attach, 0, 8,
- "attach hapn <address> <vector> ax25 <label> <rx bufsize>\
- <mtu> csma|full [ip_addr]",
- #endif
- #ifdef APPLETALK
- /* Macintosh AppleTalk */
- "0", at_attach, 0, 7,
- "attach 0 <protocol type> <device> arpa <label> <rx bufsize> <mtu> [ip_addr]",
- #endif
- #ifdef NETROM
- /* fake netrom interface */
- "netrom", nr_attach, 0, 1,
- "attach netrom [ip_addr]",
- #endif
- #ifdef PACKET
- /* FTP Software's packet driver spec */
- "packet", pk_attach, 0, 4,
- "attach packet <int#> <label> <buffers> <mtu> [ip_addr]",
- #endif
- #ifdef HS
- /* Special high speed driver for DRSI PCPA or Eagle cards */
- "hs", hs_attach, 0, 7,
- "attach hs <address> <vector> ax25 <label> <buffers> <mtu>\
- <txdelay> <persistence> [ip_addra] [ip_addrb]",
- #endif
- #ifdef SCC
- "scc", scc_attach, 0, 7,
- "\nattach scc <devices> init <addr> <spacing> <Aoff> <Boff> <Dataoff>\
- \n <intack> <vec> [p]<clock> [hdwe] [param]\
- \nattach scc <chan> slip|kiss|nrs|ax25 <label> <mtu> <speed> <bufsiz> [call] ",
- #endif
- NULLCHAR,
- };
-
- /* Packet tracing stuff */
- #include "trace.h"
- #ifdef TRACE
-
- /* Protocol tracing function pointers. Matches list of TYPE definitions
- * in iface.h.
- */
- struct trace Tracef[] = {
- #ifdef AX25
- ax_forus, ax25_dump, /* TYPE_AX25 */
- #else
- NULLFP, NULLVFP,
- #endif /* AX25 */
-
- #ifdef ETHER /* TYPE_ETHER */
- ether_forus, ether_dump,
- #else
- NULLFP, NULLVFP,
- #endif /* ETHER */
-
- NULLFP, ip_dump, /* TYPE_IP */
-
- #ifdef APPLETALK
- at_forus, at_dump, /* TYPE_APPLETALK */
- #else
- NULLFP, NULLVFP,
- #endif /* APPLETALK */
-
- #ifdef KISS /* TYPE_KISS */
- ki_forus, ki_dump,
- #else
- NULLFP, NULLVFP,
- #endif /* KISS */
-
- #ifdef NETROM /* TYPE_NETROM */
- NULLFP, ip_dump,
- #else
- NULLFP, NULLVFP,
- #endif
-
- NULLFP, ip_dump, /* TYPE_NONE */
- NULLFP, ip_dump, /* TYPE_SLIP */
-
- #ifdef PPP
- NULLFP, ppp_dump, /* TYPE_PPP */
- #else
- NULLFP, NULLVFP,
- #endif /* PPP */
- };
-
- #else /* TRACE */
-
- /* Stubs for tracing disabled */
- struct trace Tracef[] = {
- NULLFP /* No tracing at all */
- };
-
- void
- dump(iface,direction,type,bp)
- struct iface *iface;
- int direction;
- unsigned type;
- struct mbuf *bp;
- {
- }
- #endif /* TRACE */
-
-
- #if defined(AX25) && !defined(NETROM)
- /* Stubs for when ax25 is configured wihtout net/rom */
- void
- nr_route(bp,iaxp)
- struct mbuf *bp;
- struct ax25_cb *iaxp;
- {
- free_p(bp);
- }
- void
- nr_nodercv(iface,source,bp)
- struct iface *iface;
- char *source;
- struct mbuf *bp;
- {
- free_p(bp);
- }
- #endif /* defined(AX25) && !defined(NETROM) */
-
-
- #ifndef RIP
- /* Stub for routing timeout when RIP is not configured -- just remove entry */
- void
- rt_timeout(s)
- void *s;
- {
- struct route *stale = (struct route *)s;
-
- rt_drop(stale->target,stale->bits);
- }
- #endif
-
- #ifdef SERVERS
- /* "start" and "stop" subcommands */
- static struct cmds Startcmds[] = {
- #if defined(AX25) && defined(MAILBOX)
- "ax25", ax25start, 256, 0, NULLCHAR,
- #endif
- #ifdef CHATNODE
- "chatnode", conv1, 384, 0, NULLCHAR,
- #endif
- "discard", dis1, 256, 0, NULLCHAR,
- "echo", echo1, 256, 0, NULLCHAR,
- "finger", finstart, 256, 0, NULLCHAR,
- "ftp", ftpstart, 256, 0, NULLCHAR,
- #if defined(NETROM) && defined(MAILBOX)
- "netrom", nr4start, 256, 0, NULLCHAR,
- #endif
- #ifdef POP
- "pop", pop1, 256, 0, NULLCHAR,
- #endif
- #ifdef RIP
- "rip", doripinit, 0, 0, NULLCHAR,
- #endif
- "smtp", smtp1, 256, 0, NULLCHAR,
- #if defined(MAILBOX)
- "telnet", telnet1, 256, 0, NULLCHAR,
- #endif
- "ttylink", ttylstart, 256, 0, NULLCHAR,
- "remote", rem1, 256, 0, NULLCHAR,
- NULLCHAR,
- };
- static struct cmds Stopcmds[] = {
- #if defined(AX25) && defined(MAILBOX)
- "ax25", ax250, 0, 0, NULLCHAR,
- #endif
- #ifdef CHATNODE
- "chatnode", conv0, 0, 0, NULLCHAR,
- #endif
- "discard", dis0, 0, 0, NULLCHAR,
- "echo", echo0, 0, 0, NULLCHAR,
- "finger", fin0, 0, 0, NULLCHAR,
- "ftp", ftp0, 0, 0, NULLCHAR,
- #if defined(NETROM) && defined(MAILBOX)
- "netrom", nr40, 0, 0, NULLCHAR,
- #endif
- #ifdef POP
- "pop", pop0, 0, 0, NULLCHAR,
- #endif
- #ifdef RIP
- "rip", doripstop, 0, 0, NULLCHAR,
- #endif
- "smtp", smtp0, 0, 0, NULLCHAR,
- #ifdef MAILBOX
- "telnet", telnet0, 0, 0, NULLCHAR,
- #endif
- "ttylink", ttyl0, 0, 0, NULLCHAR,
- "remote", rem0, 0, 0, NULLCHAR,
- NULLCHAR,
-
- };
-
- static int
- dostart(argc,argv,p)
- int argc;
- char *argv[];
- void *p;
- {
- return subcmd(Startcmds,argc,argv,p);
- }
-
- static int
- dostop(argc,argv,p)
- int argc;
- char *argv[];
- void *p;
- {
- return subcmd(Stopcmds,argc,argv,p);
- }
- #endif /* SERVERS */
-
- /* Various configuration-dependent functions */
-
- /* Process packets in the Hopper */
- static void
- network(i,v1,v2)
- int i;
- void *v1;
- void *v2;
- {
- struct mbuf *bp;
- struct phdr phdr;
- char i_state;
-
- loop: i_state = dirps();
- while(Hopper == NULLBUF)
- pwait(&Hopper);
- restore(i_state);
-
- /* Process the input packet */
- bp = dequeue(&Hopper);
- pullup(&bp,(char *)&phdr,sizeof(phdr));
- if(phdr.iface != NULLIF)
- phdr.iface->rawrecvcnt++;
- dump(phdr.iface,IF_TRACE_IN,phdr.type,bp);
- switch(phdr.type){
- #ifdef KISS
- case TYPE_KISS:
- kiss_recv(phdr.iface,bp);
- break;
- #endif
- #ifdef AX25
- case TYPE_AX25:
- ax_recv(phdr.iface,bp);
- break;
- #endif
- #ifdef ETHER
- case TYPE_ETHER:
- eproc(phdr.iface,bp);
- break;
- #endif
- #ifdef PPP
- case TYPE_PPP:
- pproc(phdr.iface,bp);
- break;
- #endif /* PPP */
- /* These types have no link layer protocol at the point when they're
- * put in the hopper, so they can be handed directly to IP. The
- * separate types are just for user convenience when running the
- * "iface" command.
- */
- case TYPE_NETROM:
- case TYPE_SLIP:
- case TYPE_IP:
- case TYPE_NONE:
- ip_route(phdr.iface,bp,0);
- break;
- case TYPE_APPLETALK:
- default:
- free_p(bp);
- break;
- }
- /* Let everything else run - this keeps the system from wedging
- * when we're hit by a big burst of packets
- */
- pwait(NULL);
- goto loop;
- }
-
- static int
- domessage(argc,argv,p)
- int argc;
- char *argv[];
- void *p;
- {
- char msg[256];
- int sock[DEFNSOCK];
- int count, i;
-
- /* command takes the form:
-
- message <one or more socket numbers> <message>
-
- the procedure constructs a list of socket numbers from the input
- arguments, and constructs the message from the first argument that
- is not a valid socket number */
-
- count = (argc < DEFNSOCK - 1) ? argc : DEFNSOCK -1;
-
- /* get socket args */
- for (i=1; i<count ; i++)
- if((sock[i] = atoi(argv[i])) == 0)
- break;
-
- count = i;
- msg[0] = '\0';
-
- /* collect rest of args as message */
- for (;i<argc;i++) {
- strcat(msg,argv[i]);
- strcat(msg," ");
- }
-
- /* output to all sockets */
- for (i=1; i<count; i++) {
- usprintf(sock[i],"\a\n*** Message from %s:\n%s\n",Hostname,msg);
- usflush(sock[i]);
- }
- return 0;
- }
-
-